import img2pdf
import os


def images_to_pdf_with_img2pdf(image_folder, output_pdf):
    # 获取文件夹中所有图片文件
    image_files = [f for f in os.listdir(image_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp'))]
    image_files.sort()  # 按文件名排序

    # 构建完整路径
    image_paths = [os.path.join(image_folder, img) for img in image_files]

    # 转换为PDF
    if image_paths:
        with open(output_pdf, "wb") as f:
            print(image_paths)
            f.write(img2pdf.convert(image_paths))
        print(f"PDF已保存为: {output_pdf}")
    else:
        print("未找到图片文件")

# 使用示例
images_to_pdf_with_img2pdf('/Users/jimmy/Downloads/团员', '202532132769+初三（26）班+陈梓涵.pdf')